package main

import (
	"crypto/tls"
	"fmt"
	"net/http"

	"github.com/r3labs/sse/v2"
)

func main() {
	uri := "http://localhost:8080/events?stream=messages"

	client := sse.NewClient(uri)
	client.Connection.Transport = &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
	}

	err := client.SubscribeRaw(func(msg *sse.Event) {
		fmt.Println(msg.Data)
	})
	if err != nil {
		panic(err)
	}

	// err = client.Subscribe("messages", func(msg *sse.Event) {
	// 	fmt.Println(msg.Data)
	// })
	// if err != nil {
	// 	panic(err)
	// }
	//
	// events := make(chan *sse.Event)
	// err = client.SubscribeChan("messages", events)
	// if err != nil {
	// 	panic(err)
	// }
}
